#include "urlchecker.h"

/**
 * @brief URLChecker::URLChecker, URL 检测器
 */

URLChecker * URLChecker::m_URLChecker = nullptr;

URLChecker *URLChecker::instance()
{
    if(m_URLChecker == nullptr){
        m_URLChecker = new URLChecker();
    }
    return m_URLChecker;
}

/**
 * @brief URLChecker::check, 根据制定的规则链检查是否是安全的url
 * @param url
 * @return
 */
bool URLChecker::check(QString url)
{
    URLSafeFilter* cur = head;
    while(cur != nullptr){
        if(cur->check(url) == false){
            return false;
        }
        cur = cur->next;
    }
    return true;
}

void URLChecker::addFilter(URLSafeFilter *filter)
{
    URLSafeFilter* cur = head;
    while(cur->next != nullptr){
        cur = cur->next;
    }
    cur->next = filter;
}

URLChecker::URLChecker()
{
    head = new URLSafeFilter();
    RecordUrlFilter *filter = new RecordUrlFilter();
    addFilter(dynamic_cast<URLSafeFilter*>(filter));
}
